<?php 
namespace app\admin\model;
use think\Model;

	/**
	 * 获取所有的权限菜单
	 */
	class SystemModule extends Model{
		public function getmenu($arr=[],$type='menu'){
			if($arr!=[]){
				foreach ($arr as $v) {
					if($type=='menu'){
						$data[$v['mod_id']]=$this->where('parent_id='.$v['mod_id']." and module='".$type."' and visible=1")->select();
					}else{
						foreach($v as $v1){
							$data[$v1['mod_id']]=$this->where("parent_id=".$v1['mod_id']." and module='".$type."' and visible=1")->select();
						}
					}
				}
			}else{
				$data=$this->where("parent_id=0 and module='".$type."' and visible=1")->select();
			}
			return $data;
		}
		public function getAllMenu($type='all'){
			$data['menu']=$this->getmenu();
			$data['child']=$this->getmenu($data['menu']);
			if($type=='all'){
				$data['module']=$this->getmenu($data['child'],'module');
			}
			return $data;
		}

		/**
		 * 判断是否拥有相同的控制器名且方法名相同的权限
		 * @param  [type] $ctl [控制器名]
		 * @param  [type] $act [方法名]
		 * @return [type]      [查找结果]
		 */
		public function checkAction($ctl,$act,$modid=0){
			return $this->where([
				['ctl','=',$ctl],
				['act','=',$act],
				['mod_id','<>',$modid]
			])->find();
		} 
	}